package com.konne.nightmare.FastPublicOpinion.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.SizeUtils;
import com.blankj.utilcode.util.StringUtils;
import com.konne.nightmare.FastPublicOpinion.R;

/**
 * Create by ws.
 * on Data:2022/2/12  Time:下午 4:50.
 * description: ** .
 */
public class InputDialog extends Dialog {
    private InputListener inputListener;
    private String title;
    public InputDialog(@NonNull Context context) {
        super(context, R.style.loading_dialog);
    }

    public InputDialog setInputListener(InputListener inputListener) {
        this.inputListener = inputListener;
        return this;
    }

    public InputDialog setTitle(String title) {
        this.title = title;
        return this;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_input);
        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
        lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        dialogWindow.setAttributes(lp);
        dialogWindow.getDecorView().setPadding(SizeUtils.dp2px(10), 0, SizeUtils.dp2px(10), 0);
        dialogWindow.setGravity(Gravity.CENTER);
        findViewById(R.id.stv_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        findViewById(R.id.stv_submit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
                if(inputListener!=null){
                    inputListener.input(((EditText)findViewById(R.id.et_txt)).getText().toString());
                }
            }
        });
        TextView tv_title=findViewById(R.id.tv_title);
        if(!StringUtils.isEmpty(title)){
            tv_title.setText(title);
        }


    }
    public interface InputListener{
        void input(String txt);
    }
}
